<script type="text/javascript" src="java/formval.js"></script>
<script type="text/javascript">
function validateOnSubmit(formElem) {
	var elem;
	var errs=0;
	if (!validatePresent(formElem.Nachname,  'NachnameError', true))  			errs = 1;
	if (!validatePresent(formElem.Vorname,  'VornameError', true)) 	errs = 1;
	if (!validatePresent(formElem.Ort,  'OrtError', true)) 	errs = 1;
	if (!validatePresent(formElem.Plz,  'PlzError', true)) 	errs = 1;
	if (!validatePresent(formElem.Adresse,  'AdresseError', true)) 	errs = 1;
	if (!validatePresent(formElem.Email,  'EmailError', true)) 	errs = 1;
	if (!validatePresent(formElem.Tel,  'TelError', true)) 	errs = 1;
	
	if (errs==0){
		formElem.submit();
	}
};


</script>
<?php
	$ZimmerID = $_GET['ZimmerID'];
	$TouristID = $_GET["TouristID"];
	$BuchungID =  $_GET["BuchungID"];
	$AbteilungID = $_GET["AbteilungID"];
	$TagID =  $_GET["tag"];
	$MoudeTagID = $_GET["MoudeTagID"];
	//$SprachID
	
	if($_POST){
		if(!empty($_POST['TouristID'])){
			if(!empty($_POST["Nachname"])&&!empty($_POST["Vorname"])&&!empty($_POST["Ort"])&&!empty($_POST["Plz"])
			&&!empty($_POST["Adresse"])){	
				$sql="update tourist set 
				UserID= '".$_POST["UserID"]."'
				,SprachID='".$_POST["SprachID"]."'
				,Anrede='".$_POST['Anrede']."'
				,Titel='".$_POST["Titel"]."'
				,Nachname='".$_POST["Nachname"]."'
				,Vorname='".$_POST["Vorname"]."'
				,Frima='".$_POST["Frima"]."'" .
				",Ort='".$_POST["Ort"]."'" .
				",Plz='".$_POST["Plz"]."'" .
				",Adresse='".$_POST["Adresse"]."'" .
				",Email='".$_POST["Email"]."'" .
				",Tel='".$_POST["Tel"]."'" .
				",Fax='".$_POST["Fax"]."'" .
				",Plz='".$_POST["Plz"]."'" .
				"where ID=$TouristID";
				$_rd=mysql_query($sql,$_db_link);
				$sql="update buchung set 
				TouristID= '$TouristID'
				where ID=$BuchungID";
				$_rd=mysql_query($sql,$_db_link);
			}	
		}else{
			if(!empty($_POST["Nachname"])&&!empty($_POST["Vorname"])&&!empty($_POST["Ort"])&&!empty($_POST["Plz"])
			&&!empty($_POST["Adresse"])){				
			     $sql="insert into 
			     tourist (UserID,SprachID,Anrede,Titel,Nachname,Vorname,Frima,Ort,Adresse,Email,Tel,Fax,Plz) 
				values(" .
				"'".$_POST["UserID"]."'
				,'".$_GET["SprachID"]."'
				,'".$_POST["Anrede"]."'
				,'".$_POST["Titel"]."'
				,'".$_POST["Nachname"]."'
				,'".$_POST["Vorname"]."'
				,'".$_POST["Frima"]."'" .
				",'".$_POST["Ort"]."'" .
				",'".$_POST["Adresse"]."'" .
				",'".$_POST["Email"]."'" .
				",'".$_POST["Tel"]."'" .
				",'".$_POST["Fax"]."'				
				,'".$_POST["Plz"]."')";
				$_rd= mysql_query($sql,$_db_link); 
				$TouristID = mysql_insert_id();
				$sql="update buchung set 
				TouristID= '$TouristID'
				where ID=$BuchungID";
				$_rd=mysql_query($sql,$_db_link);
			}
		}
	}			
if($TouristID){
	$sql = "select * from tourist where ID=$TouristID";
	$_rd= mysql_query($sql,$_db_link); 
	if($_rd){
		$daten=mysql_fetch_array($_rd,MYSQL_ASSOC);
	}
}
	?>
	<div style="width:100%;background-color:#F1EEF3;margin:0px"> 
	<table class="tableEdit">
	<?PHP if(isset($BuchungID)){ ?>
		<tr>
		<td class="lableEdit"><?PHP  LangText("BuchungID");?>:</td>
		<td class="inputEdit"><input type="text" name="BuchungID" id="BuchungID" READONLY value='<?PHP echo $BuchungID; ?>' /></td>
		<td class="validateEdit"></td>
		</tr>
		<?PHP } ?>
	<?PHP if(isset($TouristID)){ ?>	
	<tr>
	<td class="lableEdit"><?PHP  LangText("TouristID");?>:</td>
	<td class="inputEdit"><input type="text" name="TouristID" id="TouristID" READONLY value='<?PHP echo $TouristID; ?>' /></td>
	<td class="validateEdit"></td>
	</tr>
	<?PHP } ?>
	<tr>
	<td class="lableEdit"><?PHP  LangText("Anrede");?>:*</td>
	<td class="inputEdit">
		<select name="Anrede" id="Anrede">
			<option value="0"><?PHP  LangText("Herr");?></option>
			<option value="1"><?PHP  LangText("Frau");?></option>
		</select>
	</td>
	<td class="validateEdit"><input type="label"  DISABLED  id="AnredeError" value='<?PHP LangText("AnredeError");?>' /></td>
	</tr>
	<tr>
	<td class="lableEdit"><?PHP  LangText("Titel");?>:</td>
	<td class="inputEdit">
		<select size="1" name="Titel" id="Titel">
             <option value="">---</option>
             <option value="Doktor"><?PHP  LangText("Doktor");?></option>
             <option value="Professor"><?PHP  LangText("Professor");?></option>
             <option value="ProfessorDoktor"><?PHP  LangText("ProfessorDoktor");?></option>
          </select>
	</td>
	<td class="validateEdit"></td>
	</tr>
	<tr>
	<td class="lableEdit"><?PHP  LangText("Nachname");?>:*</td>
	<td class="inputEdit"><input name="Nachname"   onchange="validatePresent(this, 'NachnameError');" id="Nachname" value='<?PHP echo $daten["Nachname"]; ?>' /></td>
	<td class="validateEdit"><input type="label"  DISABLED  id="NachnameError" value='<?PHP LangText("NachnameError");?>' /></td>
	</tr>
	<tr>
	<td class="lableEdit"><?PHP  LangText("Vorname");?>:*</td>
	<td class="inputEdit"><input name="Vorname"   onchange="validatePresent(this, 'VornameError');" id="Vorname" value='<?PHP echo $daten["Vorname"]; ?>' /></td>
	<td class="validateEdit"><input type="label"  DISABLED  id="VornameError" value='<?PHP LangText("VornameError");?>' /></td>
	</tr>
	<tr>
	<td class="lableEdit"><?PHP  LangText("Frima");?>:</td>
	<td class="inputEdit"><input name="Frima"  id="Frima" value='<?PHP echo $daten["Frima"]; ?>' /></td>
	<td class="validateEdit"></td>
	</tr>	
	<tr>
	<td class="lableEdit"><?PHP  LangText("Ort");?>:*</td>
	<td class="inputEdit"><input name="Ort"   onchange="validatePresent(this, 'OrtError');" id="Ort" value='<?PHP echo $daten["Ort"]; ?>' /></td>
	<td class="validateEdit"><input type="label"  DISABLED  id="OrtError" value='<?PHP LangText("OrtError");?>' /></td>
	</tr>
	<tr>
	<td class="lableEdit"><?PHP  LangText("Plz");?>:*</td>
	<td class="inputEdit"><input name="Plz"   onchange="validatePresent(this, 'PlzError');" id="Plz" value='<?PHP echo $daten["Plz"]; ?>' /></td>
	<td class="validateEdit"><input type="label"  DISABLED  id="PlzError" value='<?PHP LangText("PlzError");?>' /></td>
	</tr>
		<tr>
	<td class="lableEdit"><?PHP  LangText("Adresse");?>:*</td>
	<td class="inputEdit"><input name="Adresse"   onchange="validatePresent(this, 'AdresseError');" id="Adresse" value='<?PHP echo $daten["Adresse"]; ?>' /></td>
	<td class="validateEdit"><input type="label"  DISABLED  id="AdresseError" value='<?PHP LangText("AdresseError");?>' /></td>
	</tr>
		<tr>
	<td class="lableEdit"><?PHP  LangText("Land");?>:</td>
	<td class="inputEdit"><input name="Land"  id="Land" value='<?PHP echo $daten["Land"]; ?>' />	</td>
	<td class="validateEdit"></td>
	</tr>
		<tr>
	<td class="lableEdit"><?PHP  LangText("Email");?>:*</td>
	<td class="inputEdit"><input name="Email"   onchange="validatePresent(this, 'EmailError');" id="Email" value='<?PHP echo $daten["Email"]; ?>' /></td>
	<td class="validateEdit"><input type="label"  DISABLED  id="EmailError" value='<?PHP LangText("EmailError");?>' /></td>
	</tr>
		<tr>
	<td class="lableEdit"><?PHP  LangText("Tel");?>:*</td>
	<td class="inputEdit"><input name="Tel"   onchange="validatePresent(this, 'TelError');" id="Tel" value='<?PHP echo $daten["Tel"]; ?>' /></td>
	<td class="validateEdit"><input type="label"  DISABLED  id="TelError" value='<?PHP LangText("TelError");?>' /></td>
	</tr>
		<tr>
	<td class="lableEdit"><?PHP  LangText("Fax");?>:</td>
	<td class="inputEdit"><input name="Fax" id="Fax" value='<?PHP echo $daten["Fax"]; ?>' /></td>
	<td class="validateEdit"></td>
	</tr>
	
	<tr>
	<td class="lableEdit"></td>
	<td class="inputEdit">
	<input type="button"  
	onclick="window.location='index.php?<?PHP echo "tag=$TagID&page=BuchungView&MoudeTagID=$MoudeTagID&BuchungID=$BuchungID"; ?>'" class="BootenLink" value='<< <?PHP LangText("Back");?> ' />
	<input type="button"  onclick="validateOnSubmit(this.form);" class="BootenLink" value='<?PHP LangText("Speicher");?>' />
	<?php
	 if($TouristID){
	?>
	<input type="button"  
	onclick="window.location='index.php?<?PHP echo "tag=$TagID"; ?>'" class="BootenLink" value='<?PHP LangText("Fertig");?>' />
	<?php
	 }
	?>
	</td>
	<td class="validateEdit"></td>
	</tr>
	</table>
	</div>
	


